package com.thyme.content;

import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.thyme.content.configuration.UserCenterFeignConfiguration;
import com.thyme.content.resttemplate.BlockHandler;
import com.thyme.content.resttemplate.FallBackHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.spring.annotation.MapperScan;

@MapperScan("com.thyme")
@SpringBootApplication
//全局配置
//@EnableFeignClients(defaultConfiguration = UserCenterFeignConfiguration.class)
@EnableFeignClients
public class ContentApplication {

    public static void main(String[] args) {
        SpringApplication.run(ContentApplication.class, args);
    }

    @Bean
    //整合Ribbon 的注解
    @LoadBalanced
    //整合Sentinel和RestTemplate
    @SentinelRestTemplate(blockHandler = "handleException",blockHandlerClass = BlockHandler.class,
    fallback = "fallBackHandle", fallbackClass = FallBackHandler.class)
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }


}
